********************************************************************************
* ELECTORAL REPERCUSSIONS OF A PANDEMIC:  EVIDENCE FROM THE 2009 H1N1 OUTBREAK *
********************************************************************************

// NOVEMBER 2, 2021

// THIS FILE REPLICATES FIGURES 2 AND 3 IN THE MAIN TEXT OF "ELECTORAL 
// REPERCUSSIONS OF A PANDEMIC: EVIDENCE FROM THE 2009 H1N1 OUTBREAK" BY
// EMILIO GUTIÉRREZ, JAAKKO MERILÄINEN, AND ADRIÁN RUBLI

global data "XXX" // Insert data directory here
global output "XXX" // Insert output directory here

* Open data

use "$data/GMR_data_main.dta", clear

********************************************************************************

* Figure 2
* H1N1 and electoral performance of the incumbent: event-study estimates

egen munid=group(estado municipio) // generate municipality identifiers

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=. // NB. The analyses in the main text use a balanced panel
bysort id: egen sum_a=sum(a) 
drop if sum_a<6

est clear

reghdfe PAN_voteshare ib2006.year##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
local N1 = e(N)
local N2 = `N1'/6
local N3 = e(N_clust)
coefplot, vertical scheme(plotplain) keep(1997.year#c.c* 2000.year#c.c* 2003.year#c.c* 2006.year 2009.year#c.c* 2012.year#c.c*) ///
	omitted baselevels order(1997.year#c.c* 2000.year#c.c* 2003.year#c.c* 2006.year 2009.year#c.c* 2012.year#c.c*) ///
	coeflabels(1997.year#c.c* = "1997" 2000.year#c.c* = "2000" 2003.year#c.c* = "2003" 2006.year = "2006" 2009.year#c.c* = "2009" 2012.year#c.c* = "2012") ///
	ylabel(,format(%9.2f)) ytitle("Effect of excess cases (1000s)") xtitle("Election") note("Number of observations = `N1'" "Number of sections = `N2'" "Number of clusters = `N3'") yline(0) mlabposition(1) mlabel(string(@b,"%9.3f") + cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.1, "*", "")))) subtitle("Panel A: Excess cases and PAN vote share", position(11))
graph save "$output/PAN_voteshare_excess_seccion_balanced.gph", replace

test i1997.year#c.change_ari i2000.year#c.change_ari i2003.year#c.change_ari 
test i2009.year#c.change_ari i2012.year#c.change_ari

restore

preserve

gen a=1 if change_ari_z!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a)
drop if sum_a<6

reghdfe PAN_voteshare ib2006.year##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
local N1 = e(N)
local N2 = `N1'/6
local N3 = e(N_clust)
coefplot, vertical scheme(plotplain) keep(1997.year#c.c* 2000.year#c.c* 2003.year#c.c* 2006.year 2009.year#c.c* 2012.year#c.c*) ///
	omitted baselevels order(1997.year#c.c* 2000.year#c.c* 2003.year#c.c* 2006.year 2009.year#c.c* 2012.year#c.c*) ///
	coeflabels(1997.year#c.c* = "1997" 2000.year#c.c* = "2000" 2003.year#c.c* = "2003" 2006.year = "2006" 2009.year#c.c* = "2009" 2012.year#c.c* = "2012") ///
	ylabel(,format(%9.2f)) ytitle("Effect of excess cases (z-score)") xtitle("Election") note("Number of observations = `N1'" "Number of sections = `N2'" "Number of clusters = `N3'") yline(0) mlabposition(1) mlabel(string(@b,"%9.3f") + cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.1, "*", "")))) subtitle("Panel B: Excess cases (z-score) and PAN vote share", position(11))
graph save "$output/PAN_voteshare_excess_z_seccion_balanced.gph", replace

test i1997.year#c.change_ari_z i2000.year#c.change_ari_z i2003.year#c.change_ari_z
test i2009.year#c.change_ari_z i2012.year#c.change_ari_z

restore

graph combine "$output/PAN_voteshare_excess_seccion_balanced.gph" ///
	"$output/PAN_voteshare_excess_z_seccion_balanced.gph", ///
	cols(2) scheme(plotplain) xsize(16) ysize(9)
graph export "$output/fg2.eps", as(eps) preview(off) replace

********************************************************************************

* Figure 3
* Effect of the H1N1 epidemic on voter turnout

preserve

gen a=1 if change_ari!=. & turnout!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==3

reghdfe turnout ib2006.year##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(id)
local N2 =  e(N_clust)

reghdfe turnout ib2006.year##c.change_ari [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
local N1 = e(N)
local N3 = e(N_clust)
coefplot, vertical scheme(plotplain) keep(2003.year#* 2006.year 2009.year#* 2012.year#*) ///
	omitted baselevels order(2003.year#* 2006.year 2009.year#* 2012.year#*) ///
	coeflabels(2003.year#* = "2003" 2006.year = "2006" 2009.year#* = "2009" 2012.year#* = "2012") ///
	xtitle("Election") note("Number of observations = `N1'" "Number of sections = `N2'" "Number of clusters = `N3'") ylabel(,format(%9.2f)) ytitle("Effect of excess cases (1000s)") xtitle("Election") note("Number of observations = `N1'" "Number of sections = `N2'" "Number of clusters = `N3'") yline(0) mlabposition(1) mlabel(string(@b,"%9.3f") + cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.1, "*", "")))) subtitle("Panel A: Excess cases and turnout", position(11))
graph save "$output/turnout_excess_seccion_balanced.gph", replace

restore

preserve

gen a=1 if change_ari_z!=. & turnout!=.
bysort id: egen sum_a=sum(a)
keep if sum_a==3

reghdfe turnout ib2006.year##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year) cluster(id)
local N2 =  e(N_clust)

reghdfe turnout ib2006.year##c.change_ari_z [aw = total_votos], absorb(id i.munid#i.year) cluster(clues)
local N1 = e(N)
local N3 = e(N_clust)
coefplot, vertical scheme(plotplain) keep(2003.year#* 2006.year 2009.year#* 2012.year#*) ///
	omitted baselevels order(2003.year#* 2006.year 2009.year#* 2012.year#*) ///
	coeflabels(2003.year#* = "2003" 2006.year = "2006" 2009.year#* = "2009" 2012.year#* = "2012") ///
	xtitle("Election") note("Number of observations = `N1'" "Number of sections = `N2'" "Number of clusters = `N3'") ylabel(,format(%9.3f)) ytitle("Effect of excess cases (z-score)") xtitle("Election") note("Number of observations = `N1'" "Number of sections = `N2'" "Number of clusters = `N3'") yline(0) mlabposition(1) mlabel(string(@b,"%9.3f") + cond(@pval<.01, "***", cond(@pval<.05, "**", cond(@pval<.1, "*", "")))) subtitle("Panel B: Excess cases (z-score) and turnout", position(11))
graph save "$output/turnout_excess_z_seccion_balanced.gph", replace

graph combine "$output/turnout_excess_seccion_balanced.gph" ///
	"$output/turnout_excess_z_seccion_balanced.gph", ///
	cols(2) scheme(plotplain) xsize(16) ysize(9)
graph export "$output/fg3.eps", as(eps) preview(off) replace

restore
